<%@ page import="schoolsource.sql.SchoolDBSQL" %>
<%@ page import="schoolsource.model.*" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.text.*" %>
<%@ page import="schoolsource.util.Types" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="schoolsource.gui.*" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<% SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION);
   String token = (String) st.getValue(FormFields.TOKEN);
   String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
   String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
   ClassContainer classC[] = (ClassContainer[]) st.getValue("classContainer");
   UserContainer teacherC = (UserContainer) st.getValue("teacherContainer");
   int classnum = (new Integer((String) st.getValue(FormFields.CLASSNUM))).intValue();
   HomeworkContainer homeworkC[] = (HomeworkContainer[]) st.getValue("homeworkContainer");
   UserContainer studentC = (UserContainer) st.getValue("studentProgress");
   st.putValue("studentProgress", null);
   GradeContainer studentGrade[] = (GradeContainer[]) st.getValue("studentGrade");
   String noGrade = "-1.0";

AttendanceContainer ac[] = SchoolDBSQL.getSchoolDBSQL(schoolName).loadStudentClassAttendance(
       classC[classnum].getClassAssignedID(), studentC.getAssignedID());
%>

<html>
  <head></head>
  <body>
    <FORM NAME="classinfoform" METHOD="POST">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= token %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CLASSNUM %>" VALUE="<%= classnum %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
      <INPUT TYPE="HIDDEN" NAME="<%= FormFields.USRTYPE %>" VALUE="<%= loginType %>">
    </FORM>
<%
  if(classnum > -1){
    out.println("<center>");
    out.println("<table width=\"100%\" style=\"font-size:12;font-family:sans-serif;\">");
    out.println("<tr>");
    out.println("  <td width=\"33%\">&nbsp;</td>");
    out.println("  <td width=\"33% align=\"center\"><b>Progress Report</b></td>");
    out.println("  <td width=\"33% align=\"right\">" + Types.sdfMMDDYYYYslash.format((new GregorianCalendar()).getTime()) + "</td>");
    out.println("</tr>");
    out.println("</table>");
    out.println("</center><br>");
    out.println("<table style=\"font-size:11;font-family:sans-serif;\" width=\"80%\">");
    out.println("<tr>");
    out.println("  <td width=\"90\" style=\"font-weight:bold;\">Student: </td>");
    out.println("  <td>"+studentC.getFirstName().toString() + " " +  studentC.getLastName().toString() +"</td>");
    out.println("  <td width=\"90\"><b>Instructor: </b> </td>");
    out.println("  <td>"+teacherC.getFirstName().toString() + " " +  teacherC.getLastName().toString() +"</td>");
    out.println("</tr>");
    out.println("<tr>");
    out.println("  <td width=\"90\"><p align=\"left\"><b>Class Name: </b> </td>");
    out.println("  <td>"+classC[classnum].getAssociatedCourse().getCourseShortName().toString() +"</td>");
    out.println("  <td width=\"90\"><b>Time: </b></td>");
    out.println("  <td>" + classC[classnum].getClassTime().toString() + "</td>");
    out.println("</tr>");
    out.println("</table>");
  }
%>


  <table align="LEFT" style="font-size:11;font-family:sans-serif;">
  <tr><td colspan=7><hr></td></tr>
<tr align="LEFT"><th width=150>Description</th><th width=150></th><th width=90>Assigned</th><th width=90>Due</th><th width=50 align="CENTER">Score</th><th width=50 align="CENTER">Value</th><th>Comment</th></tr>
<%
  if (homeworkC != null) {
      String progressText="";
      double score=0;
      double totalGraded=0;
      for (int i = 0; i < homeworkC.length; i++) {
          out.println("<tr valign=top>");
          out.println("<td colspan=2 width=300>"+homeworkC[i].getShortName().toString()+"</td>");
          out.println("<td>"+homeworkC[i].getDateAssigned().toString()+"</td>");
          out.println("<td>"+homeworkC[i].getDateDue().toString()+"</td>");
          out.println("<td width=50 align=center>"+((!studentGrade[i].getGrade().toString().equals(noGrade)) ? ("   " + studentGrade[i].getGrade().toString()) : "")+"</td>");
          out.println("<td width=50 align=center>"+homeworkC[i].getTotalPoints().toString()+"</td>");
          out.println("<td width=150 align=left>"+((!studentGrade[i].getGrade().toString().equals(noGrade)) ? ("   " + studentGrade[i].getComment().toString()) : "")+"</td>");
          out.println("</tr>");
          if(!studentGrade[i].getGrade().toString().equals(noGrade)){
              score = score + (Double.parseDouble(studentGrade[i].getGrade().toString()));
              totalGraded = totalGraded + (Double.parseDouble(homeworkC[i].getTotalPoints().toString()));
          }
      }

      BigDecimal average = new BigDecimal(0.0);

      if(totalGraded > 0) {
          average = new BigDecimal(score);
          average.setScale(2,BigDecimal.ROUND_HALF_UP);
          BigDecimal tgbd = new BigDecimal(totalGraded);
          average = average.multiply(new BigDecimal(100.0)).divide(tgbd,2,BigDecimal.ROUND_HALF_UP);
      }
      out.println("<tr><td colspan=7><hr>");
      out.println("</td></tr>");

      out.println("<tr>");
      out.println("  <td>");
      out.println("<b>Earned Points:</b></td><td>"+score+"");
      out.println("  </td>");
      out.println("</tr>");
      out.println("<tr>");
      out.println("  <td>");
      out.println("<b>Total Possible Points:</b></td><td>"+totalGraded);
      out.println("  </td>");
      out.println("</tr>");
      out.println("<tr>");
      out.println("  <td>");
      out.println("<b>Average:</b></td><td>"+average.toString());
      out.println("  </td>");
      out.println("</tr><br>");

      out.println("<tr><td colspan=7><hr>");
      out.println("</td></tr>");
      out.println("<tr><td><b>Attendance</b>");
      out.println("</td></tr>");
        
      out.println("<tr>");
      for (int i = 0; i < ac.length; i++) {
          out.println("<tr><td>"+ac[i].getType()+"</td><td>  "+ac[i].getDate()+"</td></tr>");
      }
      out.println("</tr>");


      out.println("</table>");
      out.println("</body></html>");
  }
%>
      
  </body>
</html>
